<?php
// $Id: template.php,v 1.16.2.3 2010/05/11 09:41:22 goba Exp $

/**
 * Sets the body-tag class attribute.
 *
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
 */
function phptemplate_body_class($left, $right) {
  if ($left != '' && $right != '') {
    $class = 'sidebars';
  }
  else {
    if ($left != '') {
      $class = 'sidebar-left';
    }
    if ($right != '') {
      $class = 'sidebar-right';
    }
  }

  if (isset($class)) {
    print ' class="'. $class .'"';
  }
}

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */

function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {
  $vars['tabs2'] = menu_secondary_local_tasks();
        global $user;
  $vars['original_title'] = $vars['title'];
  if (!empty($vars['node']) && in_array($vars['node']->type, array('page', 'product'))) {
    $vars['title'] = '';
  }
  // Hook into color.module
  if (module_exists('color')) {
    _color_page_alter($vars);
  }
   if(drupal_is_front_page())
    {
        if($user->uid)
        {
            $vars['template_files'] = array('page', 'page-front');
        }
        else
        {
            $vars['template_files'] = array('page', 'page-front-anonymous');
        }   
    } else {
         if($user->uid)
        {
            if(arg(0) == 'cart' || arg(0) == 'catalog' || arg(0) == 'products' || arg(0) == 'freeproducts')
			{
		    	$vars['template_files'] = array('page', 'page-cart');
			} 
			else if(arg(0) == 'user'){
						    	$vars['template_files'] = array('page', 'page-user');
			}
			else if(arg(0) == 'tests'){
						    	$vars['template_files'] = array('page', 'page-test');

			}
			else if(arg(2) == 'take' || arg(2) == 'myresults'){
							$vars['template_files'] = array('page', 'page-test');
			}
			else
			{
				$vars['template_files'] = array('page', 'page');
			}	
        }		
        else
        {
            $vars['template_files'] = array('page', 'page-anonymous');
        }
		
	}
	
}

/**
 * Add a "Comments" heading above comments except on forum pages.
 */
function smsvidya_garland_preprocess_comment_wrapper(&$vars) {
  if ($vars['content'] && $vars['node']->type != 'forum') {
    $vars['content'] = '<h2 class="comments">'. t('Comments') .'</h2>'.  $vars['content'];
  }
}

/**
 * Returns the rendered local tasks. The default implementation renders
 * them as tabs. Overridden to split the secondary tasks.
 *
 * @ingroup themeable
 */
function phptemplate_menu_local_tasks() {
  return menu_primary_local_tasks();
}

/**
 * Returns the themed submitted-by string for the comment.
 */
function phptemplate_comment_submitted($comment) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $comment),
      '!datetime' => format_date($comment->timestamp)
    ));
}

/**
 * Returns the themed submitted-by string for the node.
 */
function phptemplate_node_submitted($node) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $node),
      '!datetime' => format_date($node->created),
    ));
}

/**
 * Generates IE CSS links for LTR and RTL languages.
 */
function phptemplate_get_ie_styles() {
  global $language;
$ie6 = "MSIE 6.0";
$ie7 = "MSIE 7.0";
$ie8 = "MSIE 8.0";
// detect browser
$browser = $_SERVER['HTTP_USER_AGENT'];

 $browser_ie = substr("$browser", 25, 8);
 $browser_chrome = substr("$browser", 86, 6);
 $browser_opera= substr("$browser", 0, 5);
 if(($browser_ie==$ie8) || ($browser_ie==$ie6)){
	 $iecss = '<link type="text/css" rel="stylesheet" media="screen" href="'. base_path() . path_to_theme() .'/style.css" />';

$iecss .= '<link type="text/css" rel="stylesheet" media="screen" href="'. base_path() . path_to_theme() .'/styleIE8.css" />';
 } 
 else if($browser_ie==$ie7)
 {	 
	$iecss = '<link type="text/css" rel="stylesheet" media="screen" href="'. base_path() . path_to_theme() .'/style.css" />';
 	$iecss .= '<link type="text/css" rel="stylesheet" media="screen" href="'. base_path() . path_to_theme() .'/styleIE7.css" />';
 }
 
 else {
$iecss = '<link type="text/css" rel="stylesheet" media="screen" href="'. base_path() . path_to_theme() .'/style.css" />';

 }
  if ($language->direction == LANGUAGE_RTL) {
    //$iecss .= '<style type="text/css" media="all">@import "'. base_path() . path_to_theme() .'/fix-ie-rtl.css";</style>';
  }

  return $iecss;
}

function smsvidya_garland_theme(&$existing, $type, $theme, $path)
{
  return array(    
    // tell Drupal what template to use for the user register form
    'user_register' => array('arguments' => array('form' => NULL),'template' => 'user-register',),
	'profile_node_form' => array('arguments' => array('form' => NULL),'template' => 'profile_node_form',), 
	'user_login' => array('arguments' => array('form' => NULL),'template' => 'user-login',), 
	'user_pass' => array('arguments' => array('form' => NULL),'template' => 'user-pass',),
//	'forum_node_form' => array('arguments' => array('form' => NULL),'template' => 'forum-node-form',),	
	//'refer_a_friend_node_form' => array('arguments' => array('form' => NULL),'template' => 'refer_a_friend_node_form',), 	
  );
}

function smsvidya_garland_uc_catalog_product_grid($products) {
global $base_url;
  $product_table = '<div class="select_cart_div_content">';
  $count = 0;
  $context = array(
    'revision' => 'themed',
    'type' => 'product',
  );
  foreach ($products as $nid) {
    $product = node_load($nid);
	/*show only non private products*/
	if($product->field_product_type[0]['value'] != '1')
	{
    $context['subject'] = array('node' => $product);
	if($product->sell_price <= 0 )
	{
	$product_table .= '<div class="highlight_freeproduct">';
	}	
	$product_table .= "<table>";
    if ($count == 0) {
      $product_table .= "<tr>";
    }
    elseif ($count % variable_get('uc_catalog_grid_display_width', 3) == 0) {
      $product_table .= "</tr><tr>";
    }

//    $titlelink = l($product->title, "node/$nid", array('html' => TRUE));
	$titlelink = $product->title;
	if(arg(1) != ""){
		$term_obj = uc_catalog_image_load(arg(1));
	    $img_path = $term_obj->filepath;
	    $img_path_id = $term_obj->fid;
	}
    if (module_exists('imagecache') && $img_path_id!="") {
     
        $imagelink = theme('imagecache', 'product_list', $img_path, '', '', '');

    }
    else {

      $imagelink = '';
    }
	 

    $product_table .= '<td class="cat_product">';
    $product_table .= '<span class="catalog-grid-image">'. $imagelink .'</span>';
	if (variable_get('uc_catalog_grid_display_title', TRUE)) {
      $product_table .= '<p><span class="catalog-grid-title blue">'. $titlelink.'</span>';
	   if($product->sell_price == '0'){
       $product_table .= '<img src="'.$base_url.'/'.path_to_theme().'/images/free_btn.png" class="free_prdt" />';
	    }
	   $product_table .= '</p>';
    }
    if (variable_get('body', TRUE)) {
      $product_table .= '<p><span class="catalog-grid-ref">'. $product->field_tag_line[0]['value'] .'</span></p>';
    }
	/*if (variable_get('uc_catalog_grid_display_model', TRUE)) {
      $product_table .= '<span class="catalog-grid-ref">'. $product->model .'</span>';
    }*/
    
    if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
      $product_table .= '<span class="red uc-price">Rs  '. round($product->sell_price) .'</span>';
    }
	if(round($product->sell_price) != '0'){
    if (module_exists('uc_cart') && variable_get('uc_catalog_grid_display_add_to_cart', TRUE)) {
      if (variable_get('uc_catalog_grid_display_attributes', TRUE)) {
        $product_table .= theme('uc_product_add_to_cart', $product);
      }
      else {
        $product_table .= drupal_get_form('uc_catalog_buy_it_now_form_'. $product->nid, $product);
		  }
	   }
	} else{
		global $user,$base_url;
		$output = user_subscribed_product($user->uid,$product->nid);
		  if(empty($output)){
			  $src = $base_url.'/'.path_to_theme().'/images/subscribe_img.gif';
			  $img = '<img src="'.$src.'"/>';
			  $path = $base_url.'/free/subscribe/'.$product->nid;
			 $product_table.="<div class='add-to-cart'>";
			 $product_table.='<a href='.$path.'>'.$img.'</a>';
			 $product_table.="</div>";
			 ?>
			<?php 			
		  } else{
			 $src = $base_url.'/'.path_to_theme().'/images/subscribed_img.gif';
			  $img = "<img src='".$src."'/>";
			  $product_table.="<div class='add-to-cart'>";
			$product_table.=$img;
			 $product_table.="</div>";
      }
    }
	
    $product_table .= '</td></tr>';
	$product_table .= '<tr><td>';
	$product_table .= '<hr /><span class="details_arrow"  id="dt'.$product->nid.'"> Details</span>';		
	if (variable_get('field_total_messages', TRUE)) {
      $product_table .= '<span class="right">Concepts / Day <input class="d_concepts" readonly="readonly" type="text" value="'. $product->field_no_messages_per_day[0]['value'] .'" /></span>';
    }
	if (variable_get('field_total_messages', TRUE)) {
      $product_table .= '<span class="right">Total Concepts <input class="t_concepts" readonly="readonly" type="text" value="'. $product->field_total_messages[0]['value'] .'" /></span>';
    }
	
	if (variable_get('field_field_duration', TRUE)) {
	$totaldays = $product->field_duration[0]['value'];
$months = floor($totaldays / 30);
$days = $totaldays - $months*30;
$months = $months == 0 ? "":$months;
$months = $months == 1 ? $months." month ":$months;
$months = $months > 1 ? $months." months ":$months;
$days = $days > 0 ? $days." days":"";
$duration  = $months > 0?$months."".$days:$days;
      $product_table .= '<span class="right">Duration <input class="du_concepts" readonly="readonly" type="text" value="'.$duration.'" /></span>';
    }
	$product_table.='<p style="clear:both;display:none;" class="details_desc" id="dt'.$product->nid.'">'.$product->body.'</p>';
    $count++;
	$product_table .= "</tr></table>";
	if($product->sell_price <= 0)
	{
	 $product_table .= "</div>";
	}
  }
  }
  $product_table .= "</div>";
  /*global $base_url;$img_path = $base_url."/".path_to_theme()."/images/buy_btn.gif";
  $product_table .= "</div><div class=\"buy_now\"><a href=\"".$base_url."/cart/checkout\"><img width=\"97\" height=\"26\" src=\"".$img_path."\"></a></div>";*/
  return $product_table;
}


function smsvidya_garland_cart_review_table($show_subtotal = TRUE) {
	
  $subtotal = 0;

  // Set up table header.
  $header = array(
    //array('data' => t('Qty'), 'class' => 'qty'),
    array('data' => t('Products'), 'class' => 'products'),
    array('data' => t('Price'), 'class' => 'price'),
  );

  $context = array();

  // Set up table rows.
  $contents = uc_cart_get_contents();
  foreach ($contents as $item) {
    $price_info = array(
      'price' => $item->price,
      'qty' => $item->qty,
    );

    $context['revision'] = 'altered';
    $context['type'] = 'cart_item';
    $context['subject'] = array(
      'cart' => $contents,
      'cart_item' => $item,
      'node' => node_load($item->nid),
    );

    $total = uc_price($price_info, $context);
    $subtotal += $total;

    $description = check_plain($item->title) . uc_product_get_description($item);

    // Remove node from context to prevent the price from being altered.
    $context['revision'] = 'themed-original';
    $context['type'] = 'amount';
    unset($context['subject']);
    $rows[] = array(
     // array('data' => t('@qty&times;', array('@qty' => $item->qty)), 'class' => 'qty'),
      array('data' => $description, 'class' => 'products'),
      array('data' => uc_price($total, $context), 'class' => 'price'),
    );
  }

  // Add the subtotal as the final row.
  if ($show_subtotal) {
    $context = array(
      'revision' => 'themed-original',
      'type' => 'amount',
    );
    $rows[] = array(
      'data' => array(array('data' => '<span id="subtotal-title">' . t('Subtotal:') . '</span> ' . uc_price($subtotal, $context), 'colspan' => 3, 'class' => 'subtotal')),
      'class' => 'subtotal',
    );
  }

  return theme('table', $header, $rows, array('class' => 'cart-review'));
}

function smsvidya_garland_uc_cart_checkout_review($panes, $form,$order) {
/*echo "<pre>";print_r($panes);echo "</pre>";*/
$content_profile = content_profile_load("profile",$order->uid);
$format ="<ul>";
foreach($order->products as $product)
{
$node_id = $product->nid;
$product_content = node_load($node_id);
$format .='<li>'.$product_content->title.'[total '.$product_content->field_total_messages[0]['value'].'messages;'.$product_content->field_no_messages_per_day[0]['value'].'sms/day]</li>';

}

$format .="</ul>";
  drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
  $output = check_markup(variable_get('uc_checkout_review_instructions', uc_get_message('review_instructions')), variable_get('uc_checkout_review_instructions_format', FILTER_FORMAT_DEFAULT), FALSE)
           .'  <table cellpadding="1" class="order_payment">
          	<tbody><tr>
            	<td><span class="blue">Billing details</span></td>
                <td>'.$panes['Delivery information'][0]['data'].'</td>
            </tr>
           <tr>
            	<td><span class="blue">Mobile Number</span><br>
				<p>(messages are sent to this number)</p>
                </td>
                <td>'. $content_profile->field_mobile[0]['value'].'</td>
            </tr>
            <tr>
            	<td><span class="blue">Description</span></td>
                <td>'.$format.'</td>
            </tr>
             <tr>
            	<td><span class="blue">Total Amount</span>
                </td>
                <td>Rs.'.$order->order_total.'</td>
            </tr>
</table>';          
          
$output .= $form;
  return $output;
}

function smsvidya_garland_userloginbar() {
  drupal_add_css(drupal_get_path('module', 'userloginbar') .'/userloginbar.css');
  global $user;
  $output = '';

  /*if (arg(0) == "user" && !is_numeric(arg(1))) {

    return;

  }*/
  if (!$user->uid) {
    $output .= drupal_get_form('user_login_block');
  }
  else if (!variable_get('disable_welcome_box', FALSE)) {
    $output .= t('<p class="user-info">Hi !user, welcome back.</p>', array('!user' => theme('username', $user)));

    $output .= theme('item_list', array(
        l(t('Your account'), 'user/'. $user->uid, array('title' => t('Edit your account'))),
        l(t('Sign out'), 'logout'),
      ));
  }

  $output = '<div id="user-login-form">'. $output .'</div>';

  return $output;
}

function smsvidya_garland_views_slideshow_singleframe_control_next($id, $view, $options) {
	global $base_url;
	$path = $base_url.'/'.path_to_theme().'/images/task-list.png';
	$view_name = $view->name;
	switch($view_name){
		case 'frontpage_catlist':
         return '<a href="#" style="position:absolute;left:1100px;top:425px;line-height:100px;" id="views_slideshow_singleframe_next_' . $id . '" class="views_slideshow_singleframe_next">' . t('<img src="'.$path.'"/>') . "</a>\n";
		break;
		case 'testpage_catlist':
			return '<a href="#" style="position:absolute;left:1100px;top:195px;line-height:100px;" id="views_slideshow_singleframe_next_' . $id . '" class="views_slideshow_singleframe_next">' . t('<img src="'.$path.'"/>') . "</a>\n";
		break;
		default:
			return '<a href="#" style="position:absolute;left:1100px;top:425px;line-height:100px;" id="views_slideshow_singleframe_next_' . $id . '" class="views_slideshow_singleframe_next">' . t('<img src="'.$path.'"/>') . "</a>\n";

		break;
	}
}

function smsvidya_garland_views_slideshow_singleframe_control_pause($id, $view, $options) {
  return '<div class="module_areaa"><a href="#" id="views_slideshow_singleframe_playpause_' . $id . '" class="views_slideshow_singleframe_pause"></a></div>';
}

function smsvidya_garland_views_slideshow_singleframe_control_previous($id, $view, $options) {
		global $base_url;
		$path = $base_url.'/'.path_to_theme().'/images/menu-collapsed-rtl.gif';
	$view_name = $view->name;
		
	switch($view_name){
	case 'frontpage_catlist':
      return '<a href="#" style="position:absolute;left:143px;top:400px;line-height:125px;" id="views_slideshow_singleframe_prev_' . $id . '" class="views_slideshow_singleframe_previous">' . t('<img src="'.$path.'"/>'). "</a>\n";
	break;
	case 'testpage_catlist':
      return '<a href="#" style="position:absolute;left:143px;top:180px;line-height:125px;" id="views_slideshow_singleframe_prev_' . $id . '" class="views_slideshow_singleframe_previous">' . t('<img src="'.$path.'"/>'). "</a>\n";
    break;
	 default:
       return '<a href="#" style="position:absolute;left:143px;top:400px;line-height:125px;" id="views_slideshow_singleframe_prev_' . $id . '" class="views_slideshow_singleframe_previous">' . t('<img src="'.$path.'"/>'). "</a>\n";
	 break;

	}
}

//function smsvidya_garland_fieldset($element){
   /* echo '<pre>';
        print_r($element);echo '</pre>';*/
    
//}

function smsvidya_garland_date_select($element) {
  $output = '';
  $class = 'container-inline-date';
  // Add #date_float to allow date parts to float together on the same line. 
  if (empty($element['#date_float'])) {
	  if($element['#id'] != "edit-field-dob-0-value"){
    $class .= ' conv-date-clear-block';
	  } 
  }
  if (isset($element['#children'])) {
    $output = $element['#children'];
  }
  
  return '<div class="'. $class .'">'. theme('form_element', $element, $output) .'</div>';
}

function smsvidya_garland_emvideo_video_thumbnail($field, $item, $formatter, $node, $no_link = FALSE, $options = array()) {
  // Thickbox requires some output, so make sure we have at least a blank string.
  $output = '';
  $options['node'] = $node;
  $width = isset($options['width']) ? $options['width'] : ($field['widget']['thumbnail_width'] ? $field['widget']['thumbnail_width'] : variable_get('emvideo_default_video_width', EMVIDEO_DEFAULT_THUMBNAIL_WIDTH));
  $height = isset($options['height']) ? $options['height'] : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('emvideo_default_video_height', EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT));

  // Get a thumbnail URL. This can be an override through $options['thumbnail_url'],
  // defined by the provider (the usual case), or a default image.
  if (isset($options['thumbnail_url']) || ($item['value'] && $item['provider'])) {
    // If we've set $options['thumbnail_url'], then we'll just use that.
    $thumbnail_url = isset($options['thumbnail_url']) ? $options['thumbnail_url'] : '';

    // Otherwise, if we have emthumb installed, then give it a chance to override our thumbnail.
    if (empty($thumbnail_url) && function_exists('emthumb_thumbnail_path')) {
      $thumbnail_url = emthumb_thumbnail_path($item);
    }

    // If we don't have a custom thumbnail, then see if the provider gives us a thumbnail.
    if (empty($thumbnail_url)) {
      $thumbnail_url = emfield_include_invoke('emvideo', $item['provider'], 'thumbnail', $field, $item, $formatter, $node, $width, $height, $options);
    }
  }

  // If we still don't have a thumbnail, then apply a default thumbnail, if it exists.
  if (empty($thumbnail_url)) {
    $default_thumbnail_url = $field['widget']['thumbnail_default_path'] ? $field['widget']['thumbnail_default_path'] : variable_get('emvideo_default_thumbnail_path', NULL);
    if ($default_thumbnail_url) {
      $thumbnail_url = $default_thumbnail_url;
    }
  }

  // Define the thumbnail link's path.
  $link_url = isset($options['link_url']) ? $options['link_url'] : 'node/'. $node->nid;

  // Define the title/alt to display for the link hover.
  $link_title = isset($options['link_title']) ? $options['link_title'] : (isset($options['title']) ? $options['title'] : (isset($field['widget']['thumbnail_link_title']) ? $field['widget']['thumbnail_link_title'] : (isset($item['title']) ? $item['title'] : variable_get('emvideo_default_thumbnail_link_title', t('See video')))));
  if (module_exists('token')) {
    // Allow the editor to use [title] tokens.
    $link_title = token_replace($link_title, 'global', $node);
  }
  $image_title = isset($options['image_title']) ? $options['image_title'] : (isset($item['title']) ? $item['title'] : $link_title);
  $image_alt = isset($options['image_alt']) ? $options['image_alt'] : (isset($item['description']) ? $item['description'] : $link_title);

  if (isset($thumbnail_url)) {
    if (!empty($options['absolute'])) {
      $thumbnail_url = url($thumbnail_url, array('absolute' => $options['absolute']));
    }
    if (isset($options['return_url'])) {
      return $options['raw'] ? $thumbnail_url : url($thumbnail_url);
    }
    $width = isset($options['width']) ? $options['width'] : NULL;
    $width = isset($width) ? $width : ($field['widget']['thumbnail_width'] ? $field['widget']['thumbnail_width'] : variable_get('emvideo_default_thumbnail_width', EMVIDEO_DEFAULT_THUMBNAIL_WIDTH));
    $height = isset($options['height']) ? $options['height'] : NULL;
    $height = isset($height) ? $height : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('emvideo_default_thumbnail_height', EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT));
    $attributes = isset($options['attributes']) ? $options['attributes'] : array();
    $attributes['width'] = isset($attributes['width']) ? $attributes['width'] : $width;
    $attributes['height'] = isset($attributes['height']) ? $attributes['height'] : $height;
    $image = theme('image', $thumbnail_url, $image_alt, $image_title, $attributes, FALSE);
    if ($no_link) {
      // Thickbox requires the thumbnail returned without the link.
      $output = $image;
    }
    else {
      $output = l($image, $link_url, array('html'=> TRUE,'attributes'=>array('rel'=>'lightvideo[|width:400px; height:300px;]')));
    }
  }
  else {
    if ($options['return_url']) {
      return $options['raw'] ? $thumbnail_url : url($link_url);
    }

    // If all else fails, then just print a 'see video' type link.
    if (!$no_link) {
      $output = l($link_title, $link_url);
    }
  }

  return $output;
}


function smsvidya_garland_fieldset($element) {
	//echo '<pre>';print_r($element);echo '</pre>';
  if (!empty($element['#collapsible'])) {
    drupal_add_js('misc/collapse.js');

    if (!isset($element['#attributes']['class'])) {
      $element['#attributes']['class'] = '';
    }

    $element['#attributes']['class'] .= ' collapsible';
    if (!empty($element['#collapsed'])) {
      $element['#attributes']['class'] .= ' collapsed';
    }
  }
$el = strip_tags(trim($element['#title']),'&nbsp;');

if(substr($el,0,11) == 'Time Period'){
	return '<div class="edit_time_period"'. drupal_attributes($element['#attributes']) .'>'. 
		  ($element['#title'] ? '<p>Time Period</p>' : '') . 
		  (!empty($element['#children']) ? $element['#children'] : '') .
		  (isset($element['#value']) ? $element['#value'] : '') .
		"</div>\n";
}
else if($el == 'Details'){
	return '<div class="edit_details"'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<h1>'. $element['#title'] .'</h1>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</div>\n";
}
else if($el == 'Education'){
	return '<div class="edit_details"'. (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</div>\n";
}
else if(substr($el,0,13) == 'Date attended'){
	return '<div class="edit_time_period"'. drupal_attributes($element['#attributes']) .'>'. 
		  ($element['#title'] ? '<p>Date attended</p>' : '') . 
		  (!empty($element['#children']) ? $element['#children'] : '') .
		  (isset($element['#value']) ? $element['#value'] : '') .
		"</div>\n";
}
else if($el == 'Convenient time for receiving SMS messages'){
	return '<div class="subscription_sms"'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<h1 style="margin-top: 10px; float:left; width:100%;">'. $element['#title'] .'</h1>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</div>\n";
}else if($el == 'Subscriptions'){
	return '<div class="edit_details subscription_edit"'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<h1 style="margin-top: 8px; float:left; width:100%">'. $element['#title'] .'</h1>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</div>\n";
} 

else {
return '<div'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<p>'. $element['#title'] .'</p>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</div>\n";

}

  }

function smsvidya_garland_content_multigroup_node_form($element) {
  $group_name = $element['#group_name'];
  $groups = fieldgroup_groups($element['#type_name']);
  $group = $groups[$group_name];
  $group_multiple = $group['settings']['multigroup']['multiple'];
  $group_fields = $element['#group_fields'];

  $table_id = $element['#group_name'] .'_values';
  $table_class = 'content-multiple-table';
  $order_class = $element['#group_name'] .'-delta-order';
  $subgroup_settings = isset($group['settings']['multigroup']['subgroup']) ? $group['settings']['multigroup']['subgroup'] : array();
  $show_label = isset($subgroup_settings['label']) ? $subgroup_settings['label'] : 'above';
  $subgroup_labels = isset($group['settings']['multigroup']['labels']) ? $group['settings']['multigroup']['labels'] : array();
  $multiple_columns = isset($group['settings']['multigroup']['multiple-columns']) ? $group['settings']['multigroup']['multiple-columns'] : 0;

  $headers = array();
  if ($group_multiple >= 1) {
    $headers[] = array('data' => '');
  }
  if ($multiple_columns) {
    foreach ($group_fields as $field_name => $field) {
      $required = !empty($field['required']) ? '&nbsp;<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';
      $headers[] = array(
        'data' => check_plain(t($field['widget']['label'])) . $required,
        'class' => 'content-multigroup-cell-'. str_replace('_', '-', $field_name),
      );
    }
    $table_class .= ' content-multigroup-edit-table-multiple-columns';
  }
  else {
    if ($group_multiple >= 1) {
      $headers[0]['colspan'] = 2;
    }
    $table_class .= ' content-multigroup-edit-table-single-column';
  }
  if ($group_multiple >= 1) {
    $headers[] = array('data' => t('Order'), 'class' => 'content-multiple-weight-header');
    if ($group_multiple == 1) {
      $rows[] = array('data' => '<span>'. t('Remove') .'</span>', 'class' => 'content-multiple-remove-header');
    }
  }
  $rows = array();

  $i = 0;
  foreach (element_children($element) as $delta => $key) {
    if (is_numeric($key)) {
      $cells = array();
      $label = ($show_label == 'above' && !empty($subgroup_labels[$i]) ? theme('content_multigroup_node_label', check_plain(t($subgroup_labels[$i]))) : '');
      $element[$key]['_weight']['#attributes']['class'] = $order_class;
      if ($group_multiple >= 1) {
        $cells[] = array('data' => '', 'class' => 'content-multiple-drag');
        $delta_element = drupal_render($element[$key]['_weight']);
        if ($group_multiple == 1) {
          $remove_element = drupal_render($element[$key]['_remove']);
        }
      }
      else {
        $element[$key]['_weight']['#type'] = 'hidden';
      }
      if ($multiple_columns) {
        foreach ($group_fields as $field_name => $field) {
          $cell = array(
            'data' => (isset($element[$key][$field_name]) ? drupal_render($element[$key][$field_name]) : ''),
            'class' => 'content-multigroup-cell-'. str_replace('_', '-', $field_name),
          );
          if (!empty($cell['data']) && !empty($element[$key][$field_name]['#description'])) {
            $cell['title'] = $element[$key][$field_name]['#description'];
          }
          $cells[] = $cell;
        }
      }
      else {
        $cells[] = $label . drupal_render($element[$key]);
      }
      if ($group_multiple >= 1) {
        $row_class = 'draggable';
        $cells[] = array('data' => $delta_element, 'class' => 'delta-order');
        if ($group_multiple == 1) {
          if (!empty($element[$key]['_remove']['#value'])) {
            $row_class .= ' content-multiple-removed-row';
          }
          $cells[] = array('data' => $remove_element, 'class' => 'content-multiple-remove-cell');
        }
        $rows[] = array('data' => $cells, 'class' => $row_class);
      }
      else {
        $rows[] = array('data' => $cells);
      }
    }
    $i++;
  }

  drupal_add_css(drupal_get_path('module', 'content_multigroup') .'/content_multigroup.css');
  $output = theme('table', array(), $rows, array('id' => $table_id, 'class' => $table_class));
  $output .= drupal_render($element[$group_name .'_add_more']);

  // Enable drag-n-drop only if the group really allows multiple values.
  if ($group_multiple >= 1) {
    drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class);
    drupal_add_js(drupal_get_path('module', 'content') .'/js/content.node_form.js');
  }

  return $output;
}

function smsvidya_garland_form_element($element, $value) {
  // This is also used in the installer, pre-database setup.
  $t = get_t();

  $output = '<div class="form-item"';
  if (!empty($element['#id'])) {
    $output .= ' id="'. $element['#id'] .'-wrapper"';
  }
  $output .= ">\n";
  $required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">*</span>' : '';



  if (!empty($element['#title'])) {
    $title = $element['#title'];
	if(trim($title) == 'To'){$cls = 'class=to_date';}
	if(trim($title) == 'Past Projects'){$cls = 'class=past_project';}
	if(trim($title) == 'Choose one'){$cls = 'class=choose_label';}
    if (!empty($element['#id'])) {
		$fivestar = substr($element['#id'],0,9);
		if($fivestar == "edit-vote"){
          $output .= '';
		} else {
      $output .= ' <label '.$cls.' for="'. $element['#id'] .'">'. $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
		}
    }
    else {
      $output .= ' <label '.$cls.'>'. $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= ' <div class="description">'. $element['#description'] ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}

function smsvidya_garland_fivestar_summary($user_rating, $average_rating, $votes, $stars = 5, $feedback = TRUE) {
  $output = '';
  $div_class = '';
  if (isset($user_rating)) {
    $div_class = isset($votes) ? 'user-count' : 'user';
    $user_stars = round(($user_rating * $stars) / 100, 1);
    $output .= '<span class="user-rating">'. t('<span>!stars</span>', array('!stars' => $user_rating ? $user_stars : '')) .'</span>';
  }
  if (isset($user_rating) && isset($average_rating)) {
    $output .= ' ';
  }
  if (isset($average_rating)) {
    $div_class = isset($votes) ? 'average-count' : 'average';
    $average_stars = round(($average_rating * $stars) / 100, 1);
   // $output .= '<span class="average-rating">'. t('<span>!stars</span>', array('!stars' => $average_stars)) .'</span>';
  }
  if (isset($user_rating) && isset($average_rating)) {
    $div_class = 'combo';
  }

/*  if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
    $output .= ' <span class="total-votes">'. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .'</span>';
    $div_class = 'count';
  }
  elseif (isset($votes)) {
    $output .= ' <span class="total-votes">('. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .')</span>';
  }

 if ($votes === 0) {
    $output = '<span class="empty">'. t('No votes yet') .'</span>';
  }*/
  $output = '<div class="fivestar-summary fivestar-summary-'. $div_class . ($feedback ? ' fivestar-feedback-enabled' : '') .'">'. $output .'</div>';
  return $output;
}

function smsvidya_garland_quiz_progress($question_number, $num_of_question, $jumper = FALSE, $time_limit = FALSE) {
  $output = '';
  return $output;
}


function smsvidya_garland_quiz_user_summary($quiz, $questions, $score, $summary) {
  // Set the title here so themers can adjust.
  drupal_set_title(check_plain($quiz->title));

  if (!$score['is_evaluated']) {
    $msg = t('Parts of this @quiz have not been evaluated yet. The score below is not final.', array('@quiz' => QUIZ_NAME));
    drupal_set_message($msg, 'status');
  }

  // Display overall result.
  $output = '';
  $output .= '<div id="quiz_score_possible" style="display:none;" class="test">'. t('You got %num_correct of %question_count possible points.', array('%num_correct' => $score['numeric_score'], '%question_count' => $score['possible_score'])) .'</div>'."\n";
  $output .= '<div id="quiz_score_percent" style="display:none;">'. t('Your score was: @score %', array('@score' => $score['percentage_score'])) .'</div>'."\n";
  if (isset($summary['passfail']))
    $output .= '<div id="quiz_summary">'. $summary['passfail'] .'</div>'."\n";
  if (isset($summary['result']))
    $output .= '<div id="quiz_summary">'. $summary['result'] .'</div>'."\n";
  // Get the feedback for all questions.
  $output .= drupal_get_form('quiz_report_form', $questions, FALSE, TRUE);
  return $output;
}

function smsvidya_garland_multichoice_response($data) {
  $rows = array();
  $p = drupal_get_path('module', 'multichoice') . '/theme/images';
  foreach($data as $id => $alternative) {
    $cols = array();
    $rowspan = drupal_strlen($alternative['feedback']) > 0 ? 2: 1;
    $not = '';
    if ($alternative['is_chosen']) {
      switch ($alternative['is_correct']) {
        case 0:
          $cols[] = array(
            'data' => theme('image', "$p/wrong.png", t('Wrong'), t('This answer is wrong'), array('class' => 'feedback-icon')),
            'width' => 35,
            'rowspan' => $rowspan,
            'class' => 'selector-td',
          );
          break;
        case 1:
          $cols[] = array('data' => theme('image', "$p/almost.png", t('Almost correct'), t('This answer is correct, but there is an answer that gives a higher score'), array('class' => 'feedback-icon')),
            'width' => 35,
            'rowspan' => $rowspan,
            'class' => 'selector-td',
          );
          break;
        case 2:
          $cols[] = array(
            'data' => theme('image', "$p/correct.png", t('Correct'), t('This answer is correct'), array('class' => 'feedback-icon')),
            'width' => 35,
            'rowspan' => $rowspan,
            'class' => 'selector-td',
          );
          break;
      }
    }
    else {
      if ($alternative['is_correct'] == 2) {
        $cols[] = array(
          'data' => theme('image', "$p/should.png", t('Should have chosen'), t("This answer is correct, but you didn't choose it"), array('class' => 'feedback-icon')),
          'width' => 35,
          'rowspan' => $rowspan,
          'class' => 'selector-td',
        );
      }
      else {
        $cols[] = array(
          'data' => '',
          'width' => 35,
          'rowspan' => $rowspan,
          'class' => 'selector-td',
        );
      }
    }
    $cols[] = $alternative['answer'];
    $rows[] = $cols;
    if ($rowspan == 2) {
      $rows[] = array('<strong>' . t('Feedback:') . '</strong><div class="quiz_answer_feedback">' . $alternative['feedback'] . '</div>');
    }
  }
  return theme('table', NULL, $rows);  
}
function smsvidya_garland_uc_catalog_block($menu_tree) {
  $output = '<ul class="catalog menu">';

  foreach ($menu_tree->children as $branch) {
    list($inpath, $html) = _uc_catalog_navigation_custom($branch);
    $output .= $html;
  }

  $output .= '</ul>';

  return $output;
}

function _uc_catalog_navigation_custom($branch) {
  static $terms;
  static $breadcrumb;
  static $types;

  if (empty($types)) {
    $types = uc_product_types();
  }

  $num = 0;
  foreach ($types as $type) {
    $num += taxonomy_term_count_nodes_custom($branch->tid, $type);
  }

  // No nodes in category or descendants. Not in path and display nothing.
  if (!$num) {
    return array(FALSE, '');
  }

  $branch_path = uc_catalog_path($branch);
  if (!isset($breadcrumb)) {
    $breadcrumb = drupal_get_breadcrumb();
  }
  $vid = variable_get('uc_catalog_vid', 0);
  if ($_GET['q'] ==  $branch_path) {
    // The URL points to this term.
    $here = TRUE;
  }
  else {
    $here = FALSE;
  }
  if (!isset($terms)) {
    $terms = taxonomy_node_get_terms_by_vocabulary(menu_get_object('node', 1), $vid);
  }
  // Determine whether to expand menu item.
  if ((arg(0) == 'node' && array_key_exists($branch->tid, $terms))) {
    $inpath = FALSE;
    foreach ($breadcrumb as $link) {
      if (strpos($link, drupal_get_path_alias($branch_path)) !== FALSE) {
        $inpath = TRUE;
      }
    }
  }
  else {
    $inpath = $here;
  }

  // Checks to see if node counts are desired in navigation
  $num_text = '';
  if (variable_get('uc_catalog_block_nodecount', TRUE)) {
    $num_text = ' ('. $num .')';
  }
  $lis = array();
  $expand = variable_get('uc_catalog_expand_categories', FALSE);
  $link = l($branch->name . $num_text, $branch_path);
  if ($expand || count($branch->children)) {
    foreach ($branch->children as $twig) {
      // Expand if children are in the menu path. Capture their output.
      list($child_in_path, $lis[]) = _uc_catalog_navigation($twig);
      if ($child_in_path) {
        $inpath = $child_in_path;
      }
    }
  }
  $output = theme("uc_catalog_item", $here, $link, $lis, $expand, $inpath, count($branch->children));

  // Tell parent category your status, and pass on output.
  return array($inpath, $output);
}

function taxonomy_term_count_nodes_custom($tid, $type = 0) {
  static $count;

  if (!isset($count[$type])) {
    // $type == 0 always evaluates TRUE if $type is a string
    if (is_numeric($type)) {
      $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 GROUP BY t.tid'));  }
    else {
     // $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type);	  
	  $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM term_node t INNER JOIN node n ON t.vid = n.vid LEFT JOIN content_type_product as cp on n.nid = cp.nid WHERE n.status = 1 AND n.type = '%s' AND (cp.field_product_type_value != 1 or cp.field_product_type_value is null)  GROUP BY t.tid"), $type);
	  
	  //echo "SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid". $type;
    }
    $count[$type] = array();
    while ($term = db_fetch_object($result)) {
      $count[$type][$term->tid] = $term->c;
    }
	/*echo "<pre>";
	print_r($count);
	echo "</pre>";*/
 }
  $children_count = 0;
  foreach (smsvidya_garland_taxonomy_term_children($tid) as $c) {
    $children_count += taxonomy_term_count_nodes_custom($c, $type);
  }
  return $children_count + (isset($count[$type][$tid]) ? $count[$type][$tid] : 0);  
}


function smsvidya_garland_taxonomy_term_children($tid) {
  static $children;

  if (!isset($children)) {
    $result = db_query('SELECT tid, parent FROM {term_hierarchy}');
    while ($term = db_fetch_object($result)) {
      $children[$term->parent][] = $term->tid;
    }	
  }
  return isset($children[$tid]) ? $children[$tid] : array();
}